#include "NLSaturationDesigner.h"
#include "ui_NLSaturationDesigner.h"

#include <QMessageBox>

using namespace RafMat::SimInterface;

NLSaturationDesigner::NLSaturationDesigner(QWidget *parent) :
    NonlinearDesignerBase(parent),
    ui(new Ui::NLSaturationDesigner)
{
    ui->setupUi(this);
}

NLSaturationDesigner::~NLSaturationDesigner()
{
    delete ui;
}

void NLSaturationDesigner::attachModel(RafMat::SimInterface::IConfigurableSPtr ctrl)
{
    m_nlConf = ctrl;

    try
    {
        ui->edWorkingPoint->setText(QString::fromStdString(m_nlConf->getParameter("WorkingPoint")));
        ui->edNLGain->setText(QString::fromStdString(m_nlConf->getParameter("NonlinearityGain")));
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}

void NLSaturationDesigner::applySettings()
{
    try
    {
        m_nlConf->setParameter("WorkingPoint", ui->edWorkingPoint->text().toStdString());
        m_nlConf->setParameter("NonlinearityGain", ui->edNLGain->text().toStdString());
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}
